package com.etone.autotesting.manager.impl;

import org.apache.log4j.Logger;

import com.etone.app.support.result.JsonResult;
import com.etone.autotesting.conditions.ObjectCondition;
import com.etone.autotesting.dao.impl.ConditionSearchDao;
import com.etone.ejb.core.support.Jsoner;

/**
 * 
 * @author chenzhichao
 * 
 */
public class ServiceThreadRunable implements Runnable {

	protected static Logger logger = Logger.getLogger(ServiceThreadRunable.class.getName());
	/**
 * 
 */
	private String function;
	/**
 * 
 */
	private String condition;
	/**
 * 
 */
	private String serviceName;
	/**
 * 
 */
	private String methodName;

	private String serviceInfo;

	/**
	 * @return the function
	 */
	public String getFunction() {
		return function;
	}

	/**
	 * @param function
	 *            the function to set
	 */
	public void setFunction(String function) {
		this.function = function;
	}

	/**
	 * @return the condition
	 */
	public String getCondition() {
		return condition;
	}

	/**
	 * @param condition
	 *            the condition to set
	 */
	public void setCondition(String condition) {
		this.condition = condition;
	}

	/**
	 * @return the serviceName
	 */
	public String getServiceName() {
		return serviceName;
	}

	/**
	 * @param serviceName
	 *            the serviceName to set
	 */
	public void setServiceName(String serviceName) {
		this.serviceName = serviceName;
	}

	/**
	 * @return the methodName
	 */
	public String getMethodName() {
		return methodName;
	}

	/**
	 * @param methodName
	 *            the methodName to set
	 */
	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	/**
	 * @param serviceInfo
	 *            the serviceInfo to set
	 */
	public void setServiceInfo(String serviceInfo) {
		this.serviceInfo = serviceInfo;
	}

	/**
	 * @return the serviceInfo
	 */
	public String getServiceInfo() {
		return serviceInfo;
	}

	@Override
	public void run() {
		ObjectCondition objectCondition = new ObjectCondition();
		objectCondition.setCondition(condition);
		double jsonLength = objectCondition.getJoinLength();
		// objectCondition.setCurConditionIndex(2);
		for (int i = 0; i < jsonLength; i++) {
			String jsonCondition = objectCondition.getJsonCondition();
			System.out.println(i + ":" + jsonCondition);			
			Long startTime = System.currentTimeMillis();
			JsonResult result = null;
			String logInfo = function + "||" + jsonCondition + "||";
			try {
				result = ConditionSearchDao.getInstance().ServiceSearchData(objectCondition.getPage(), objectCondition.getFilter(), objectCondition.getOrder(), serviceName, methodName, serviceInfo);
			} catch (Exception ex) {
				logger.error(logInfo + ex.toString());
				continue;
			}
			Long endTime = System.currentTimeMillis();
			Long runTime =(endTime - startTime);
			System.out.println("执行结果：" + (result == null) + ",执行时间：" + runTime);
			if(result != null)
				logger.info(logInfo + result.getMessage());
		}
	}

}
